<?php
class Admin_Model_NodeConfigMapper {
	protected $_dbTable;
	
	public function setDbTable($dbTable)
    {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function getDbTable()
    {
        if (null === $this->_dbTable) {
            $this->setDbTable('Admin_Model_DbTable_NodeConfig');
        }
        return $this->_dbTable;
    }
	
	public function fetchAll()
    {
        $resultSet = $this->getDbTable()->fetchAll();
        $entries   = array();
        foreach ($resultSet as $row) {
            $entry = new Admin_Model_NodeConfig();
            $entry->setId($row->Id)
        		  ->setName($row->Name)
                  ->setController($row->Controller);
            $entries[] = $entry;
        }
        return $entries;
    }
    public function find($id)
    {
    	$t = $this->getDbTable();
    	$row = $t->find($id)->current();
        return is_null($row)? null : new Admin_Model_NodeConfig($row->toArray());
    }
}

?>